# -*- coding: utf-8 -*-
'''
Created on Aug 30, 2013

@author: LONG HOANG GIANG
'''

import pyLib
import os


diemcong = {'1': 1.5, '2NT': 1, '2': 0.5, '3': 0}


class ThiSinh():
    
    khoithi = ''
    tongdiem = 0
    tongdiemkv = 0
    khuvuc = 3
    
    def __init__(self, _khoithi, _khuvuc, _tongdiem):
        self.khoithi = _khoithi
        self.tongdiem = _tongdiem
        self.khuvuc = _khuvuc
        self.tongdiemkv = self.congdiemcong(_khuvuc, _tongdiem)
    
    def congdiemcong(self, khuvuc, tongdiem):
        return tongdiem + diemcong[khuvuc]

def locdanhsach(_manganh, _khoithi='*'):
    dsthisinh = []
    filepath = "c:/Users/LONG HOANG GIANG/Desktop/ds.txt"
    data = pyLib.file_get_content(filepath).split("\n")
    for line in data:
        arr = line.split(' ')
        n = len(arr)
        if _manganh != arr[n-2]:  continue
        tongdiem = float(arr[n-3]) / 100
        khuvuc = arr[n-7]
        khoithi = arr[1]
        if _khoithi != '*' and khoithi != _khoithi: continue
        p = ThiSinh(khoithi, khuvuc, tongdiem)
        dsthisinh.append(p)
    
    return dsthisinh

def countif(danhsach, tongdiem):
    c = 0
    for ts in danhsach:
        if ts.tongdiemkv >= tongdiem: c += 1
    return c

if __name__ == '__main__':
    
    nganh = {'qtkd': 'D340101', 'lkt': 'D380107', 'kt': 'D310101'}
    danhsach = locdanhsach(nganh['lkt'], '*')
    print 'Tong so thi sinh: ', len(danhsach)
    print '>=18:', countif(danhsach, 18)
    print '>=18.5:', countif(danhsach, 18.5)
    print '>=19:', countif(danhsach, 19)
    print '>=19.5:', countif(danhsach, 19.5)
    print '>=20:', countif(danhsach, 20)
    print '>=21:', countif(danhsach, 21)
    
    
    os._exit(1)
    
